﻿
@{ 
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            @*<label class="layui-form-label">ID</label>*@
            <div class="layui-input-block">
                <input type="hidden" name="userID" id="userID" lay-verify="required" lay-reqtext="组织ID是必填项，岂能为空？" placeholder="请输入组织ID" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            @*<label class="layui-form-label">组织ID</label>*@
            <div class="layui-input-block">
                <input type="hidden" name="deptID" id="deptID" lay-verify="required" lay-reqtext="组织ID是必填项，岂能为空？" placeholder="请输入组织ID" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户编号</label>
            <div class="layui-input-block">
                <input type="text" name="userCode" id="userCode" lay-verify="required" lay-reqtext="用户编号是必填项，岂能为空？" placeholder="请输入用户编号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">拼音码</label>
            <div class="layui-input-block">
                <input type="text" name="firstPY" id="firstPY" lay-verify="required" lay-reqtext="拼音码是必填项，岂能为空？" placeholder="请输入拼音码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录名</label>
            <div class="layui-input-block">
                <input type="text" name="loginName" id="loginName" lay-verify="required" lay-reqtext="登录名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="pwd" id="pwd" lay-verify="required" lay-reqtext="密码是必填项，岂能为空？" placeholder="请输入登录名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户姓名</label>
            <div class="layui-input-block">
                <input type="text" name="userName" id="userName" lay-verify="required" lay-reqtext="用户姓名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户类型</label>
            <div class="layui-input-block">
                <input type="text" name="userType" id="userType" lay-verify="required" lay-reqtext="用户类型是必填项，岂能为空？" placeholder="请输入用户姓名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="true" title="启用" checked="">
                <input type="radio" name="status" value="false" title="禁用">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <script src="~/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

    <script>

        //（4） 前端：浏览器请求服务器的时候，要带上JWT
        $.ajaxSetup({
            beforeSend: function (xhr) {
                if (localStorage.getItem("token") !== null) {
                    //（4） 前端：浏览器请求服务器的时候，要带上JWT
                    xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("token"));
                }
            }
        });

        layui.use('form', function () {

           

            var form = layui.form;
            //监听提交
            form.on('submit(demo1)', function (data) {
                console.log(data);
                $.ajax({
                    url: "https://localhost:44398/api/UsersAPI/Update",
                    type: "post",
                    data: data.field,
                    success: function (data) {
                        console.log(data);
                        if (data > 0) {
                            layer.msg("修改成功", function () {
                                parent.location.href = "/UsersWeb/Show";
                            });
                        } else {
                            layer.msg("修改失败");
                            return;
                        }
                    }
                })
                return false;
            });

            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });
             //文档就绪反填数据
            $(function () {

                $.ajax({
                    url: "https://localhost:44398/api/UsersAPI/Fantian?id= "+@ViewBag.ids,
                    type: "get",
                    success: function (d) {
                        $("#userID").val(@ViewBag.ids);
                        $("#deptID").val(d.data.deptID);
                        $("#userCode").val(d.data.userCode);
                        $("#firstPY").val(d.data.firstPY);
                        $("#loginName").val(d.data.loginName);
                        $("#pwd").val(d.data.pwd);
                        $("#userName").val(d.data.userName);
                        $("#userType").val(d.data.userType);
                    }
                })
            })
        });
    </script>

</body>
</html>
